﻿using BLL.Interface;
using Common;
using Common.Extensions;
using Microsoft.AspNetCore.Mvc;

namespace TianXiaHuiForumManagementSystem.Controllers.Api
{
    [Route("Api/[controller]")]
    [ApiController]
    public class CaptchaController : ControllerBase
    {
        private readonly ICaptchaBLL _captchaBLL;
        public CaptchaController(
            ICaptchaBLL captchaBLL
            )
        {
            _captchaBLL = captchaBLL;
        }
        /// <summary>
        /// 生成验证码
        /// </summary>
        /// <param name="appId"></param>
        /// <returns></returns>
        [HttpGet, Route("GetImageCaptcha")]
        public async Task<ActionResult> GetImageCaptcha(string appId)
        {
            var result = await _captchaBLL.GetImageCaptcha(appId, DateTime.Now.AddMinutes(15));
            return File(result, "image/jpeg");
        }
        /// <summary>
        /// 获取邮箱验证码
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        [HttpGet, Route("GetEmailCaptcha")]
        public async Task<string> GetEmailCaptcha(string email)
        {
            var result = await _captchaBLL.GetEmailCaptcha(email, DateTime.Now.AddMinutes(15));
            return result.ToJsonFormat();
        }
    }
}
